/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/summary-ranges
   @Language: C++
   @Datetime: 20-01-16 15:21
   */

class Solution {
public:
	vector<string> summaryRanges(vector<int>& nums) {
		vector<string> vs;
		if (nums.size()==0) return vs;
		int i=0, j=0, k=0;
		for(i=j=0, k=1; k<nums.size(); ++k){
			if (nums[j]+1==nums[k]) j=k;
			else {
				if (i<j) vs.push_back(to_string(nums[i])+"->"+to_string(nums[j]));
				else vs.push_back(to_string(nums[i]));
				i=j=k;
			}
		}
		if (i<j) vs.push_back(to_string(nums[i])+"->"+to_string(nums[j]));
		else vs.push_back(to_string(nums[i]));
		return vs;
	}
};
